package main

import (
	"flag"

	"charging_pile/netty/internal/config"
	iot "charging_pile/netty/internal/device"
	"charging_pile/netty/internal/mq/nats"
	"charging_pile/netty/internal/svc"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/core/service"
)

var configFile = flag.String("f", "etc/device.yaml", "the config file")

func main() {
	flag.Parse()
	var c config.Config

	conf.MustLoad(*configFile, &c)

	logx.DisableStat()

	if err := c.SetUp(); err != nil {
		panic(err)
	}

	svcContext := svc.NewServiceContext(c)
	natConn := nats.MustNewNatsConn(svcContext)
	iotServer := iot.NewIoTService(svcContext)

	group := service.NewServiceGroup()
	group.Add(natConn)
	group.Add(iotServer)

	// fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	defer group.Stop()
	group.Start()
}
